#define UNIT_TESTING
#include "CUnit/Basic.h"
#include "find_sub_str.c"

void test_find_substring_normal(void) {
    char str[] = "bbccaadd";
    char substr[] = "aa";
    CU_ASSERT_EQUAL(4, find_substring(str, strlen(str), substr));
}

void test_find_substring_at_start(void) {
    char str[] = "aabbccdd";
    char substr[] = "aa";
    CU_ASSERT_EQUAL(0, find_substring(str, strlen(str), substr));
}

void test_find_substring_at_end(void) {
    char str[] = "bbccddaa";
    char substr[] = "aa";
    CU_ASSERT_EQUAL(6, find_substring(str, strlen(str), substr));
}

void test_find_substring_not_found(void) {
    char str[] = "bbccdd";
    char substr[] = "aa";
    CU_ASSERT_EQUAL(-1, find_substring(str, strlen(str), substr));
}

void test_find_substring_empty_substr(void) {
    char str[] = "bbccdd";
    char substr[] = "";
    CU_ASSERT_EQUAL(-1, find_substring(str, strlen(str), substr));
}

void test_find_substring_longer_substr(void) {
    char str[] = "bbccdd";
    char substr[] = "bbccddee";
    CU_ASSERT_EQUAL(-1, find_substring(str, strlen(str), substr));
}

void test_find_substring_case_sensitive(void) {
    char str[] = "bbccAAdd";
    char substr[] = "aa";
    CU_ASSERT_EQUAL(-1, find_substring(str, strlen(str), substr));
}

int main() {
    CU_initialize_registry();

    CU_pSuite suite = CU_add_suite("find_substring_tests", NULL, NULL);
    CU_add_test(suite, "test_find_substring_normal", test_find_substring_normal);
    CU_add_test(suite, "test_find_substring_at_start", test_find_substring_at_start);
    CU_add_test(suite, "test_find_substring_at_end", test_find_substring_at_end);
    CU_add_test(suite, "test_find_substring_not_found", test_find_substring_not_found);
    CU_add_test(suite, "test_find_substring_empty_substr", test_find_substring_empty_substr);
    CU_add_test(suite, "test_find_substring_longer_substr", test_find_substring_longer_substr);
    CU_add_test(suite, "test_find_substring_case_sensitive", test_find_substring_case_sensitive);

    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    CU_cleanup_registry();

    return 0;
}